import { ref, Ref } from 'vue';
export default function useSetTimeout(fn: () => void, delay = 0) {
    const timer: Ref<NodeJS.Timeout | null> = ref(null);
    const start = () => {
        timer.value = setTimeout(() => {
            fn();
        }, delay);
    };
    const stop = () => {
        if(timer.value){
            clearTimeout(timer.value);
            timer.value = null;
        }
    };
    const reload = () => {  
        stop();
        start();
    };
    return {
        start,
        stop,
        reload
    };
}